/**
 * Created by Admin on 2015/7/20.
 */
package com.lunchEveryDay.controller;

import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import com.lunchEveryDay.dao.UserDao;
import com.lunchEveryDay.dao.UserLunchDao;
import com.lunchEveryDay.entity.LunchSchedule;
import com.lunchEveryDay.entity.User;
import com.lunchEveryDay.entity.UserLunch;
import com.lunchEveryDay.service.LunchScheduleService;
import com.lunchEveryDay.service.UserLunchService;
import com.lunchEveryDay.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
public class IndexController {
	@Resource
	private UserService userService;
	@Resource
	private UserLunchService userLunchService;
	@Resource
	private LunchScheduleService lunchScheduleService;
//	@RequestMapping(value="/greeting", method= RequestMethod.GET)
//	@ResponseBody
//	public Object greetingGet(@RequestParam(value = "name", required = false, defaultValue = "World") String name) {
//		return "Hallo "+name;
//	}

	@RequestMapping(value="/index")
	public String Index() {
		return "index";
	}
	@ResponseBody
	@RequestMapping(value="/LunchByUsername")
	public Object LunchByUsername(@RequestParam(value = "username") String username) {
		User user= userService.getUserByUsername(username);
		return userLunchService.getUserLunchByUser(user);
	}
	@ResponseBody
	@RequestMapping(value="/LunchScheduleByUsername")
	public Object LunchScheduleByUsername(@RequestParam(value = "username") String username) {
		User user= userService.getUserByUsername(username);
		return userLunchService.getLunchScheduleByUser(user);
	}
	@ResponseBody
	@RequestMapping(value="/getLunchPeopleNum")
	public Integer getLunchPeopleNum(@RequestParam(value = "lunchId") long lunchId)  {
		LunchSchedule lunchSchedule=lunchScheduleService.get(lunchId);
		if(null==lunchSchedule)
			return null;
		return lunchSchedule.getPeopleNum();
	}
}